package com.loong.seller.business;

import com.loong.common.mybatis.business.AbstractBusiness;
import com.loong.seller.common.backend.param.ShopTypeQueryParam;
import com.loong.seller.model.ShopType;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Description:
 * @Author: hzp
 * @Date: 2020-12-3 9:26
 */
@Component
public class ShopTypeBusiness extends AbstractBusiness<ShopType> {


    /**
     * 分页查询
     * @param param 查询条件
     * @return 返回店铺
     */
    public List<ShopType> query(ShopTypeQueryParam param){
        Condition condition = new Condition(ShopType.class);
        Example.Criteria criteria = condition.createCriteria();
        buildQueryCriteria(param,criteria);
        return findByCondition(condition);
    }
    //这里根据业务需求构造条件
    private void buildQueryCriteria(ShopTypeQueryParam param,Example.Criteria criteria){
        if(ObjectUtils.isNotEmpty( param.getShopTypeName())){
            criteria.andEqualTo("shopTypeName", param.getShopTypeName());
            // criteria.andLike("name",param.getName());
        }
        if(ObjectUtils.isNotEmpty(param.getStatus())){
            criteria.andEqualTo("status",param.getStatus());
        }
        if(ObjectUtils.isNotEmpty(param.getType())){
            criteria.andEqualTo("type",param.getType());
        }
    }
}
